package com.itheima.web;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * company: www.abc.com
 * Author: 29746
 * Create Data: 2020/11/10
 */
@RestController
@RequestMapping("/checkitem")
@Api("检查项")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;
    //
    // @PostMapping("/add")
    // @ApiOperation("新增检查项")
    // public void add(@RequestBody CheckItem checkItem){
    //     checkItemService.save(checkItem);
    // }


    @GetMapping("/findAll")
    @ApiOperation("查询所有检查项") //逻辑删除后修改的查询方法
    public List<CheckItem> findAll(){
        return checkItemService.findAll();
    }

    @PostMapping("/save")
    @ApiOperation("新增和修改检查项")
    public void save(@RequestBody CheckItem checkItem){
        checkItemService.saveOrUpdate(checkItem);
    }

    @GetMapping("/remove/{id}")
    @ApiOperation("删除检查项")
    public boolean deleteById(@PathVariable("id") Long id){
        boolean flag = checkItemService.deleteById(id);
        return flag;
    }


    @PostMapping("/findByPage")
    @ApiOperation("分页查询检查项")
    @PreAuthorize("hasAuthority('search_checkitem')")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
       return checkItemService.findByPage(queryPageBean);
    }


}
